﻿Imports DevExpress.XtraEditors

Public Class ucDigitalKeyboard
    Private b_0 As Boolean

    Public Property B_01 As Boolean
        Get
            Return b_0
        End Get
        Set(value As Boolean)
            b_0 = value
        End Set
    End Property

    Private b_1 As Boolean

    Public Property B_02 As Boolean
        Get
            Return b_1
        End Get
        Set(value As Boolean)
            b_1 = value
        End Set
    End Property

    Private _txt As TextEdit

    Public Property Txt As TextEdit
        Get
            Return _txt
        End Get
        Set(value As TextEdit)
            _txt = value
            lblNum.Text = value.Tag
            Me.ForeColor = Color.Black
            Me.Left = value.FindForm().Width / 2 - Me.Width / 2
            Me.Top = value.FindForm().Height / 2 - Me.Height / 2
        End Set
    End Property

    Private Sub ucDigitalKeyboard_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        btnPoint.Enabled = B_01
        btnComma.Enabled = B_02
    End Sub
    Private Sub Button_Click(sender As Object, e As EventArgs) Handles btn3.Click, btn2.Click, btn1.Click, bttn7.Click, btn8.Click, btn9.Click, btn6.Click, btn5.Click, btn4.Click, btnPoint.Click, btn0.Click, btnBackspace.Click, btnComma.Click, btnEnter.Click, btnClear.Click
        Dim tmpText As String = txtNum.Text
        Dim btn As Button = sender
        Try
            If btn.Name = "btnPoint" Then
                If tmpText.Length = 0 Then
                    tmpText &= "0"
                End If
                Dim tmpComma As String = tmpText.Remove(0, tmpText.Length - 1)
                If tmpComma.Equals("-") Then
                    tmpText &= "0."
                Else
                    tmpText &= "."
                End If
                'If tmpComma.ToString.Contains(".") = False Then
                '    tmpText &= "."
                'Else

                'End If
            ElseIf btn.Name = "btnComma" Then
                If tmpText.Length = 0 Then
                    tmpText &= "0"
                End If
                Dim tmpComma As String = tmpText.Remove(0, tmpText.Length - 1)
                If tmpComma.Equals(".") = True Then
                    tmpText = tmpComma
                End If
                If tmpComma.Equals("-") = False Then
                    tmpText &= "-"
                End If
            ElseIf btn.Name = "btnBackspace" Then
                If tmpText.Length > 0 Then
                    tmpText = tmpText.Substring(0, tmpText.Length - 1)
                End If
            ElseIf btn.Name = "btnClear" Then
                tmpText = String.Empty
            ElseIf btn.Name = "btnEnter" Then
                'SendKeys.Send("{Tab}")
                Try
                    Txt.Text = tmpText
                    Txt.Focus()
                Catch ex As Exception
                    'Txt.Value = orgNum
                End Try
                Me.Hide()
            Else
                'If tmpText.ToString.Contains(".") Then
                '    If tmpText.Split(".")(1).Equals(".0") = False Then
                '        tmpText = tmpText.Substring(0, tmpText.Length - 1)
                '    End If
                'End If
                tmpText &= btn.Text
            End If
            txtNum.Text = tmpText



        Catch ex As Exception

        End Try

    End Sub

    'Private Sub ucDigitalKeyboard_LostFocus(sender As Object, e As EventArgs) Handles Me.LostFocus
    '    Me.Dispose()
    'End Sub
End Class
